
import QtQuick 1.0
//import Qt.labs.folderlistmodel 1.0

// prend exemple sur http://www.pluzz.fr/c-dans-l-air.html?sortie=rss
Rectangle {
    id: podcastRect
    property alias rssSource : xmlModel.source
    signal selectPodcast(string videoId)
    
    color: "#3E606F"
    width: 1000
    height: 800
    focus: true
    
    Component.onCompleted: {
      rssSource = 'http://www.pluzz.fr/c-dans-l-air.html?sortie=rss'
    }
    
    XmlListModel {
	id: xmlModel
	//source: "http://feeds.feedburner.com/Pluzz-Actusociete?format=xml"
	query: "/rss/channel/item"
	XmlRole { name: "title"; query: "title/string()" }
	XmlRole { name: "pubDate"; query: "pubDate/string()" }
	XmlRole { name: "description"; query: "description/string()" }
	XmlRole { name: "imageSrc"; query: "image/string()" }
	XmlRole { name: "link"; query: "link/string()" }
    }
  
     Rectangle {
        id: rectDetail
        anchors.left: listItems.right
        width: 500
        height: 400
        color: "transparent"
        smooth: true
        Image {id:imgDet; smooth: true ; fillMode: Image.PreserveAspectFit;width: 400;height: 400 }
        Text {
	  id: txtDet
	  wrapMode : Text.Wrap
	  anchors.top : imgDet.bottom
	  width:rectDetail.width-50
	  text: ''
	  color: "white"
	  font.pixelSize: 20
	}	
    }
	
    ListView {
	    id: listItems
	    focus: true
	    x:20
	    width: 500
	    height: parent.height
            model:xmlModel
	    delegate: Item {
			id: container
			width: ListView.view.width-60;
			height: 60;
			anchors.leftMargin: 10;
			anchors.rightMargin: 10

			Rectangle {
			    id: content
			    anchors.centerIn: parent; width: container.width - 40; height: container.height - 10
			    color: "transparent"
			    smooth: true
			    radius: 10
			    Rectangle { anchors.fill: parent; anchors.margins: 3; color: "#91AA9D"; smooth: true; radius: 8 }
			    Text {
			      id: label
			      anchors.verticalCenter: content.verticalCenter
			      //anchors.left:img.right
			      text: title
			      color: "#193441"
			      font.pixelSize: 20
			    }	
			}

			MouseArea {
			    id: mouseArea
			    anchors.fill: parent
			    hoverEnabled: true
			    onClicked: {
				ListView.view.currentIndex = index;
				container.forceActiveFocus();
			    }
			}

			Keys.onPressed: {
				    if (event.key == Qt.Key_Return) {
					console.log("selected :"  + link );
					podcastRect.selectPodcast(link);
				    }
			}
			
			states: State {
			    name: "active"; when: container.activeFocus
			    PropertyChanges { target: content; color: "#FCFFF5"; scale: 1.2 }
			    PropertyChanges { target: container;  x:30 }
			    //PropertyChanges { target: label; font.pixelSize: 25 }
			    PropertyChanges { target: imgDet; source: ('http://www.pluzz.fr/' + imageSrc) }
			    PropertyChanges { target: txtDet; text: description }
			    
			}

			transitions: Transition {
			    NumberAnimation { properties: "scale"; duration: 100 }
			}
		    }
	    spacing:20
	    preferredHighlightBegin : 150
	    preferredHighlightEnd : 500
	    highlightRangeMode : ListView.ApplyRange
	}

        
}
